<?php	


class scores {
	// Arrays are indexed by $week
	var $startDay = array();	// start day for this week
	var $startMonth = array();	// start month for this week
	var $startYear = array();	// start year for this week
	var $endDay = array();		// end day for this week
	var $endMonth = array();	// end month for this week
	var $endYear = array();		// end year for this week
	
	function scores()
	{
	}
	
	function GetNumberPlayers()
	{
		return mysqli_num_rows($result);
	}
	
	function CheckWeeks($thisWeek, $cDatabase, $connect)
	{
		$playerCode = array();
		$playerName = array();
		$weekScore = array();
	
		$compareWeek = getWeekVariable($thisWeek);

		// Get the list of players
		$selectArray[0] = '*';
		$result = $cDatabase->selectFromDatabase($connect, 'playerlist', $selectArray, NULL, NULL, NULL, NULL);
		
		$maxWeeks = $cDatabase->GetMaxWeeks($connect);

		// Go through each row and add player codes to this array
		for ($i = 0; $i < mysqli_num_rows($result); $i++)
		{
			$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
			$playerCode[$i] = $row['playerCode'];
		}
		
		for ($i = 0; $i < sizeof($playerCode); $i++)
		{
			$result = $cDatabase->selectFromDatabase($connect, 'playerlist', $selectArray, 'playerCode', $playerCode[$i], NULL, NULL);
			$row = mysqli_fetch_array($result, MYSQLI_ASSOC);
			
			$playerName[$i] = $row['playerName'];
			$weekScore[$i] = $row[$compareWeek];
			for($week = 0; $week <= $maxWeeks; $week++)
			{
				$weekVariable = getWeekVariable($week);
				$totalWeekScoreArray[$week] += $row[$weekVariable];
			}
		}
		$updateFlag = 0;
		$weekCheckFlag = OK;
		
		// Do some checks on the weeks
		for ($i = 1; $i <= $thisWeek; $i++)
		{ 
			if ($i < $thisWeek)	// If this is a week before the week we are updating
			{
				// Check all weeks already have scores added
				if ($totalWeekScoreArray[$i] == 0)
				{
					$weekCheckFlag = ENTRY_NOT_PRESENT;
					echo"<BR>WARNING [".$weekCheckFlag."] Week ".$i." does not have valid scores yet.";
				}
			}
			else if ($i == $thisWeek)	// If this is the same week as the week we intend to update
			{
				// Check this week doesn't already have scores added
				if ($totalWeekScoreArray[$i] > 0)
				{
					$weekCheckFlag = ENTRY_THIS_ALREADY_PRESENT;
					echo"<BR>WARNING [".$weekCheckFlag."] Week ".$thisWeek." already has entries for scores.";
					$updateFlag = 1;	// Indicate that we will be overwriting scores for this week
				}
			}
			else	// If this is a week after the week we are updating
			{
				// Check all weeks don't have scores added yet
				if($totalWeekScoreArray[$i] != 0)
				{
					$weekCheckFlag = ENTRY_FUTURE_ALREADY_PRESENT;
					echo"<BR>WARNING [".$weekCheckFlag."] Week ".$i." already has entries for scores.";
				}
			}
		}
	}
}

?>